<template>
	<view>
		<detail-info :item="detail"></detail-info>
		<!-- 评论标题 -->
		<view class="u-comment-title">
			最新评论 1
		</view>
		<!-- 评论列表 -->
		<view class="uni-comment u-comment">
			<block v-for="(item, index) in comment.list" :key="index">
				<comment-list :item="item" :index="index"></comment-list>
			</block>
		</view>
		<view style="height: 120upx;"></view>
		<!-- 评论输入框 -->
		<user-chat-bottom @send="send"></user-chat-bottom>
		
		<!-- 分享 -->
		<more-share :show="shareshow" @togle="togle"></more-share>
	</view>
</template>

<script>
	import detailInfo from '../../components/detail/detail-info.vue';
	import commentList from '../../components/detail/comment-list.vue';
	import userChatBottom from '../../components/user-chat/user-chat-bottom.vue';
	import moreShare from '../../components/common/more-share.vue';
	import time from '../../common/time.js';
	export default {
		components:{
			detailInfo,
			commentList,
			userChatBottom,
			moreShare
		},
		data() {
			return {
				shareshow:false,
				comment: {
					count: 20,
					list:[]
				},
				detail: {
					avatar: '../../static/images/avatar/nan1.jpg',
					nickname: '马保国',
					sex: 0, // 0：男，1：女
					age: 55,
					isfollow: false,
					title: '今天撸猫猫',
					cover: '../../static/images/shuijiao.jpg',
					piclist:['../../static/images/shuijiao.jpg','../../static/images/cbd.jpg'],
					video: false,
					share: false,
					address: '苏州 虎丘',
					sharenum: 25,
					commentnum: 200,
					likenum:20
				}
			}
		},
		onLoad(e) {
			// 获取传值内容
			this.initData(JSON.parse(e.detailData))
			this.getComment();
		},
		onNavigationBarButtonTap(e) {
			if(e.index === 0) {
				// todo 分享
				this.togle();
			}
		},
		methods: {
			togle(){
				this.shareshow = !this.shareshow;
			},
			// 获取评论
			getComment(){
				let arr = [
					//一级评论
					{
						id: 1,
						fid: 0, 
						avatar: '../../static/images/avatar/nan2.jpg',
						nickname: '高渐离',
						time: '1605516686',
						data: '我是中单法王',
						gstime: ''
					},
					// 二级评论
					{
						id: 2,
						fid: 1, 
						avatar: '../../static/images/avatar/nv1.jpg',
						nickname: '上官婉儿',
						time: '1605517686',
						data: '你让我咋看，滑稽',
						gstime: ''
					},
					// 二级评论
					{
						id: 3,
						fid: 1, 
						avatar: '../../static/images/avatar/nv2.jpg',
						nickname: '马可露露',
						time: '1605527686',
						data: '我就想当个安静的美少女，嘤嘤嘤',
						gstime: ''
					}
				];
				for (var i = 0; i < arr.length; i++) {
					arr[i].gstime = time.gettime.gettime(arr[i].time);
				}
				this.comment.list = arr;
			},
			// 初始化数据
			initData(obj){
				// 修改窗口标题
				uni.setNavigationBarTitle({
					title: obj.title
				});
			},
			// 发送数据
			send(text){
				console.log(text);
				let date = time.gettime.gettime(new Date().getTime());
				let obj = {
					id: 4,
					fid: 3, 
					avatar: '../../static/images/avatar/nan3.jpg',
					nickname: '嬴政',
					time: date,
					data: text,
					gstime: ''
				}
				this.comment.list.push(obj);
			}
		}
	}
</script>

<style>
	/* 评论 */
	.u-comment-title{
		padding: 20upx;
		font-size: 30upx;
		font-weight: bold;
	}
	.u-comment{
		padding: 0 20upx;
	}
	
</style>
